package com.runshu.runshuwulian.ui.activity;


import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;

import com.runshu.runshuwulian.R;
import com.runshu.runshuwulian.base.BaseActivity;
import com.runshu.runshuwulian.ui.fragment.BuHuoFrg;
import com.runshu.runshuwulian.ui.fragment.MineFrg;
import com.runshu.runshuwulian.ui.fragment.XiaoHaoFrg;
import com.runshu.runshuwulian.widget.TopTitleBar;
import com.runshu.runshuwulian.widget.ViewPager;
import com.runshu.runshuwulian.widget.YRadioButton;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MainActivity extends BaseActivity {


    @BindView(R.id.frag_social_rb_xiaohao)
    YRadioButton mFragSocialRbXiaohao;
    @BindView(R.id.frag_social_rb_buhuo)
    RadioButton mFragSocialRbBuhuo;
    @BindView(R.id.frag_social_rb_kucun)
    RadioButton mFragSocialRbKucun;
    @BindView(R.id.frag_social_rb_wode)
    RadioButton mFragSocialRbWode;
    @BindView(R.id.frag_social_bottom_rg)
    RadioGroup mFragSocialBottomRg;
    @BindView(R.id.frag_social_bottom_container)
    LinearLayout mFragSocialBottomContainer;
    @BindView(R.id.frag_social_container)
    ViewPager mFragSocialContainer;
    @BindView(R.id.toolbar)
    TopTitleBar mToolbar;
    private List<Fragment> mFragments;

    @Override
    protected int setContentViewResId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {

        initData();
        bindListener();
//       mFragSocialBottomRg.postDelayed( ()->{ },300 );

    }

    private void initData() {
        mToolbar.setTitle("润术供应链");
        mFragments = new ArrayList<>();
        mFragments.add(new XiaoHaoFrg());
        mFragments.add(new BuHuoFrg());
//        mFragments.add( new KuCunFrg() );
        mFragments.add(new MineFrg());
        mFragSocialContainer.setOffscreenPageLimit(mFragments.size());
        mFragSocialContainer.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mFragments.get(position);
            }

            @Override
            public int getCount() {
                return mFragments.size();
            }
        });
        mFragSocialBottomRg.check(  R.id.frag_social_rb_xiaohao );
    }

    private void bindListener() {
        mFragSocialBottomRg.setOnCheckedChangeListener((group, checkedId) -> {
            switch (checkedId) {
                case R.id.frag_social_rb_xiaohao:
                    mFragSocialContainer.setCurrentItem(0, false);
                    mToolbar.setTitle("润术供应链");
                    break;
                case R.id.frag_social_rb_buhuo:
                    mFragSocialContainer.setCurrentItem(1, false);
                    mToolbar.setTitle("润术供应链");
                    break;
//                case R.id.frag_social_rb_kucun:
//                    UtilUMeng.tab_click( 3 );
//                    mToolbar.setVisibility( View.GONE );
//                    mToolbar.clearRightChild();
//                    fragSocialContainer.setCurrentItem( 2, false );
//                    showHomeView( false, "我的" );
//                    break;
                case R.id.frag_social_rb_wode:
                    mFragSocialContainer.setCurrentItem(2, false);
                    mToolbar.setTitle("我的");
                    break;
            }
        });

    }
}